package cn.stylefeng.guns.modular.business.service.Impl;


import cn.hutool.core.util.ObjectUtil;
import cn.stylefeng.guns.modular.business.entity.CanalFirstClassify;
import cn.stylefeng.guns.modular.business.mapper.CanalFirstClassifyMapper;
import cn.stylefeng.guns.modular.business.service.CanalFirstClassifyService;
import cn.stylefeng.roses.kernel.db.api.factory.PageFactory;
import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CanalFirstClassifyServiceImpl extends ServiceImpl<CanalFirstClassifyMapper, CanalFirstClassify> implements CanalFirstClassifyService {



    @Override
    public CanalFirstClassify detail(CanalFirstClassify canalFirstClassify) {
        return this.queryCar(canalFirstClassify);
    }

    @Override
    public PageResult<CanalFirstClassify> findPage(CanalFirstClassify canalFirstClassify) {
        LambdaQueryWrapper<CanalFirstClassify> wrapper = createWrapper(canalFirstClassify);
        Page<CanalFirstClassify> sysRolePage = this.page(PageFactory.defaultPage(), wrapper);
        return PageResultFactory.createPageResult(sysRolePage);
    }

    @Override
    public  List<Map<String,Object>> findFirstList(CanalFirstClassify canalFirstClassify) {
        LambdaQueryWrapper<CanalFirstClassify> wrapper = this.createWrapper(canalFirstClassify);
        List<CanalFirstClassify>  list = this.list(wrapper);
        List<Map<String,Object>> mapList=new ArrayList<>();
        for(CanalFirstClassify files:list){
            Map<String,Object> map = new HashMap<String,Object>();
            map= JSONObject.parseObject(JSONObject.toJSONString(files),Map.class);
            if("时空大运河·大事记".equals(map.get("canalFirstClassifyName"))){
                map.put("index","riverEvent");
                map.put("class","el-icon-tickets");
            }
            if("时空大运河·图志".equals(map.get("canalFirstClassifyName"))){
                map.put("index","riverMap");
                map.put("class","el-icon-picture-outline");
            }
            if("河道·河政".equals(map.get("canalFirstClassifyName"))){
                map.put("index","riverAdministration");
                map.put("class","el-icon-place");
            }
            if("工程科技".equals(map.get("canalFirstClassifyName"))){
                map.put("index","riverEngineering");
                map.put("class","el-icon-setting");
            }
            if("漕运航运".equals(map.get("canalFirstClassifyName"))){
                map.put("index","riverTransport");
                map.put("class","el-icon-ship");
            }
            if("城镇".equals(map.get("canalFirstClassifyName"))){
                map.put("index","riverCity");
                map.put("class","el-icon-office-building");
            }
            if("文化".equals(map.get("canalFirstClassifyName"))){
                map.put("index","riverCulture");
                map.put("class","el-icon-reading");
            }
            if("遗产·考古".equals(map.get("canalFirstClassifyName"))){
                map.put("index","riverHeritage");
                map.put("class","el-icon-camera");
            }
            if("人物·故事".equals(map.get("canalFirstClassifyName"))){
                map.put("index","riverPerson");
                map.put("class","el-icon-user");
            }
            if("文献典籍".equals(map.get("canalFirstClassifyName"))){
                map.put("index","riverBook");
                map.put("class","el-icon-collection");
            }
            if("运河百科".equals(map.get("canalFirstClassifyName"))){
                map.put("index","riverWiki");
                map.put("class","el-icon-files");
            }
            mapList.add(map);
        }

        return mapList;
    }

    /**
     * 获取信息
     */
    private CanalFirstClassify queryCar(CanalFirstClassify canalFirstClassify) {
        CanalFirstClassify firstClassfiy =this.getById(canalFirstClassify.getId());
        if (ObjectUtil.isEmpty(firstClassfiy)) {
            return null;
        }
        return firstClassfiy;
    }

    /**
     * 创建查询wrapper
     */
    private LambdaQueryWrapper<CanalFirstClassify> createWrapper(CanalFirstClassify canalFirstClassify) {
        LambdaQueryWrapper<CanalFirstClassify> queryWrapper = new LambdaQueryWrapper<>();

        String name = canalFirstClassify.getCanalFirstClassifyName();
        queryWrapper.like(ObjectUtil.isNotEmpty(name), CanalFirstClassify::getCanalFirstClassifyName, name);

        return queryWrapper;
    }
}
